﻿using CleanArchitecture.Infrastructure.Entities.Settings;
using CleanArchitecture.Infrastructure.Interfaces;
using CleanArchitecture.Infrastructure.Interfaces.AdminUsers;
using CleanArchitecture.Infrastructure.Models.SystemManage;
using CleanArchitecture.Web.Backend.BackendApi;
using CleanArchitecture.Web.Factories;
using Microsoft.AspNetCore.Mvc;

namespace CleanArchitecture.Web.Controllers.Backend
{
    public class BackendHomeController : BaseAdminController
    {
        private readonly IAdminUserService _adminuserService;
        private readonly IWorkContext _workContext;
        private readonly IAdminUserModelFactory _adminuserModelFactory;
        private readonly ISettingService _settingService;
        public BackendHomeController(IAdminUserService adminuserService,
            IWorkContext workContext,
            IAdminUserModelFactory adminusermodelFact,
            ISettingService settingService)
        {
            this._adminuserService = adminuserService;
            this._workContext = workContext;
            this._adminuserModelFactory = adminusermodelFact;
            this._settingService = settingService;
        }
        //[AuthorizeAdmin(Core.Configuration.AuthorizeType.AdminOnly)]
        //[AllowAnonymous]
        public IActionResult Index()
        {
            var CurrentAdminUserModel = _adminuserModelFactory.PrepareAdminUser();
            ViewBag.AdminUserPassworkExpiredInfo = string.Empty;
            if (_adminuserService.PasswordIsExpired(_workContext.CurrentAdminUser))
                ViewBag.AdminUserPassworkExpiredInfo = ApiResponseMessages.AdminUserPassworkExpired;
            return View(CurrentAdminUserModel);
        }

        //[AuthorizeAdmin(Core.Configuration.AuthorizeType.AdminOnly)]
        public IActionResult Welcome()
        {
            ViewBag.PageTitle = "后台首页 - >_<";
            PrepareSystemNoticeModel();
            return View();
        }

        protected void PrepareSystemNoticeModel()
        {
            var noticesearchModel = new SystemNoticeSearchModel();
            noticesearchModel.SetGridPageSize(9);  //首页布局最多显示9条分页屏幕不会出现上下滚动条
            ViewBag.NoticeSearchModel = noticesearchModel;
            var clientSettingsPC = _settingService.LoadSetting<ClientSitePCSettings>();
            var clientSettingsMobile = _settingService.LoadSetting<ClientSiteMobileSettings>();
            ViewBag.ClientPCSettings = clientSettingsPC;
            ViewBag.ClientMobileSettings = clientSettingsMobile;
        }
    }
}